package com.dbs.donatebooksystem.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dbs.donatebooksystem.pojo.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

//根据account和password查询用户是否存在
//存在返回user,不存在则为NULL
@Mapper
public interface userMapper extends BaseMapper<User> {
    @Select("select * from user where account=#{account} ")
    User getByAccountAndPassword(User user);

    @Select("select * from user where id =#{id}")
    User getUserById(int id);

    @Select("select * from user where account = #{account}")
    User selectUserByAccount(@Param("account") String account);

    List<User> selectUsers(@Param("id")Integer id, @Param("account")String account,@Param("nickname")String nickname);

    @Select("select * from user where id=#{id}")
    User selectAUser(Integer id);

    @Select("SELECT \n" +
            "    statu AS name, \n" +
            "    COUNT(*) AS value\n" +
            "FROM \n" +
            "    user\n" +
            "WHERE \n" +
            "    statu IN (0, 1)\n" +
            "GROUP BY \n" +
            "    statu;")
    List<Map<String, Object>> selectUserStatu();

    @Delete("delete from user where id = #{id}")
    void deleteUserById(@Param("id") Integer id);
}
